//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CXmlNodeData.h>
///	@path	~/src/database/xdata/
///	@date	2007/12/03
///	@desc	XML type node entry.

#pragma once

#include "xeres.h"

#include "lib/utilities/dict.h"

#include "object/varying_data.h"

#include "database/database.h"
#include "database/IData.h"

namespace xeres {

	/*!
		\class	CXmlNodeData
		\brief	XML type node entry.
	*/
	class CXmlNodeData : public IData
	{
	public:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		CXmlNodeData( const Key& name );

		/// \dtor
		virtual ~CXmlNodeData( void );

		//@}

		DECL_IOBJECT_CLASS( CXmlNodeData , IData );

	public:

		/// \impl
		virtual bool SetBool( bool val );
		/// \impl
		virtual bool SetInt( int val );
		/// \impl
		virtual bool SetFloat( float val );
		/// \impl
		virtual bool SetPair( const Pair<float>& val );
		/// \impl
		virtual bool SetVector( const Vector<float>& val );
		/// \impl
		virtual bool SetQuat( const Quat<float>& val );
		/// \impl
		virtual bool SetColor( const Color4& val );
		/// \impl
		virtual bool SetMatrix( const Matrix<float>& val );
		/// \impl
		virtual bool SetString( const WString& val );

		/// \impl
		virtual bool GetBool( bool& val ) const;
		/// \impl
		virtual bool GetInt( int& val ) const;
		/// \impl
		virtual bool GetFloat( float& val ) const;
		/// \impl
		virtual bool GetPair( Pair<float>& val ) const;
		/// \impl
		virtual bool GetVector( Vector<float>& val ) const;
		/// \impl
		virtual bool GetQuat( Quat<float>& val ) const;
		/// \impl
		virtual bool GetColor( Color4& val ) const;
		/// \impl
		virtual bool GetMatrix( Matrix<float>& val ) const;
		/// \impl
		virtual bool GetString( WString& val ) const;

		/// \impl
		virtual bool GetInfo( DataInfo& datainfo );

		/// \impl
		virtual const WString& GetVarTypeName( void ) const;

		/// \impl
		virtual const ClassID GetVarTypeID( void ) const;

		/// \impl
		virtual const Key& GetKey( void ) const;

		/// \impl
		virtual bool GetAttribute( const WString& attr , WString& value , const WString& defaultVal = _S("") );

		/// \impl
		virtual bool SetAttribute( const WString& attr , const WString& value );

		/// \impl
		virtual size_t GetAttributeCount( void );

		/// \impl
		virtual void * AttributeBegin( void );

		/// \impl
		virtual bool AttributeIterate( void * context , WString& name , WString& value , bool iterateNext );

		/// \impl
		virtual void AttributeEnd( void * context );

		/// \impl
		virtual RefPass<IData> NewChild( const Key& key );

		/// \impl
		virtual size_t GetChildCount( void );

		/// \impl
		virtual RefPass<IData> GetChild( const Key& key );

		/// \impl
		virtual RefPass<IData> GetChild( size_t index );

		/// \impl
		virtual bool GetChildInfo( const Key& key , DataInfo& info );

		/// \impl
		virtual bool GetChildInfo( size_t index , DataInfo& info , WString& name );

		/// \impl
		virtual bool FindChildIndex( const Key& key , size_t& index );

		/// \impl
		virtual RefPass<IData> FindChild( const Key& key , size_t& index );

		/// \impl
		virtual bool Save( void );

		/// \impl
		virtual bool Reload( void );

	private:

		// key
		Key				m_key;

		// data
		VaryingData		m_data;

		// child node
		std::vector< Ref< CXmlNodeData > >	m_children;

		// attributes
		dict<WString,WString>	m_attrs;
	};

} // namespace xeres
